//
//  UITableView+Empty.m
//  QMCXDriver
//
//  Created by Massimo on 2017/4/24.
//  Copyright © 2017年 Massimo. All rights reserved.
//

#import "UITableView+Empty.h"

@implementation UITableView (Empty)


- (void)showEmpty:(NSString*)imageName title:(NSString*)title callback:(isShowCallBack)callBack{
    self.tableFooterView = nil;
    if (callBack == nil) return;
    BOOL isShowEmpty = callBack();
    if (isShowEmpty == NO)  return;
    UIView *header = self.tableHeaderView;
    CGRect footerFrame = self.bounds;
    footerFrame.size.height = CGRectGetHeight(self.bounds) - CGRectGetHeight(header.bounds); 
    UIView *footer = [[UIView alloc] initWithFrame:footerFrame];
    self.tableFooterView = footer;
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
    [footer addSubview:imageView];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
    label.font = [UIFont systemFontOfSize:15];
    label.textColor = [UIColor whiteColor];
    label.text = title;
    [footer addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(footer);
    }];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(footer);
        make.bottom.equalTo(label.mas_top).offset(-10);
    }];
}
- (void)showNetworkError{
    [self showEmpty:IMAGENAME_ERROT_NETWORK title:ERROR_NETWORK_INFO callback:^BOOL{
        return YES;
    }];
}
@end
